package com.kaka.bus.adapter;

import android.content.Context;
import android.support.annotation.Nullable;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.kaka.bus.R;
import com.kaka.bus.bean.Product;

import java.util.List;

/**
 * Created by zhangqi on 2016/11/2.
 */

public class MainProductAdapter extends BaseQuickAdapter<Product, BaseViewHolder> {

    public static final String TYPE_USE = "a";
    public static final String TYPE_UNUSE = "d";

    private Context mContext;


    public MainProductAdapter(int layoutResId, @Nullable List<Product> data, Context context) {
        super(layoutResId, data);
        mContext = context;
    }

    @Override
    protected void convert(BaseViewHolder helper, Product item) {
        helper.setText(R.id.item_mainproduct_name, item.getProduct_name())
                .setText(R.id.item_mainproduct_info, item.getProduct_description());

        ImageView img = helper.getView(R.id.item_mainproduct_img);
        String icon = item.getProduct_icon();

        if (icon != null) {
            Glide.with(mContext).load(icon).crossFade().placeholder(R.mipmap.home_xiaoedaikuan)
                    .error(R.mipmap.home_xiaoedaikuan).into(img);
        }else{
            Glide.with(mContext).load(R.mipmap.home_xiaoedaikuan).into(img);
        }

        String status = item.getStatus().toLowerCase();

        if(TYPE_USE.equals(status)){
            helper.setVisible(R.id.item_mainproduct_arraw,true)
                    .setVisible(R.id.item_mainproduct_tips,false);
        }else if (TYPE_UNUSE.equals(status)){
            helper.setVisible(R.id.item_mainproduct_arraw,false)
                    .setVisible(R.id.item_mainproduct_tips,true);
        }
    }
}
